<template>
  <el-dialog
    :title="title"
    :visible.sync="visible"
    :append-to-body="true"
  >
    <el-form ref="form" class="form-center-wrapper">
      <nb-form
        type="datetime"
        v-model="executeTime"
        required
        prop="executeTime"
        label="定时发布时间"
      ></nb-form>
    </el-form>
    <div slot="footer">
      <nb-button large type="plain" @click="visible = false">取消</nb-button>
      <nb-button large type="primary" @click="confirm">确认</nb-button>
    </div>
  </el-dialog>
</template>

<script>
  import NbForm from '@/components/nb-form'
  import {formatDate} from '@/common/utils'
  import Mixin from '@/common/mixin'
  export default {
    data () {
      return {
        title: '',
        visible: false,
        executeTime: '',
        type: false,
        timeModel: {
          objectId: '',
          executeTime: ''
        }
      }
    },
    mixins: [Mixin],
    components: {
      NbForm
    },
    props: ['search', 'selectRow'],
    methods: {
      show (row, title, type = false) {
        this.type = type
        this.title = title || '添加定时发布时间'
        this.executeTime = row.executeTime ? new Date(row.executeTime) : ''
        this.timeModel.objectId = row.id
        this.visible = true
      },
      confirm () {
        let value = this.validator(this.$refs.form)
        if (!value) {
          this.timeModel.executeTime = formatDate(this.executeTime, 'YYYY-MM-DD HH:mm:ss')
          this.$store.dispatch('SCHEDULE_RELEASE', {param: this.timeModel}).then(res => {
            if (res.success) {
              this.$message.success(this.type ? '修改定时发布时间成功' : '添加定时发布时间成功！')
              this.visible = false
              this.search()
            } else {
              this.$message.error(res.msg)
            }
          })
        }
      }
    },
    mounted () {
    }
  }
</script>

<style lang="scss">

</style>
